// pages/mine/concat/concat.js
Page({

  /**
   * 页面的初始数据
   */
  data: {  list:[],windowheight:603,offset:0

  },

 
  onLoad: function (options) {
    this.getdata()
    var now = new Date();
       
    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1<10?'0'+ (now.getMonth() + 1)  : now.getMonth() + 1 
    var day = now.getDate()<10?'0'+ (now.getDate())  : now.getDate()     
   
    var hh = now.getHours()<10?'0'+ (now.getHours())  : now.getHours()   
    var mm = now.getMinutes()<10?'0'+ (now.getMinutes())  : now.getMinutes() 
    console.log(year+'-'+month+'/'+day+'-'+hh+':'+mm);
    
        this.setData({
          time:year+'-'+month+'/'+day+'-'+hh+':'+mm
        })
        
  },
   ask(e){
      
     this.debonuce(()=>{
      let obj={}
      obj.value=e.currentTarget.dataset.title
      console.log(wx.getStorageSync('avatarUrl'));
      
      obj.avatar=wx.getStorageSync('avatarUrl')
      let list=this.data.list.concat(obj)
      this.setData({list})
      this.getreply(e.currentTarget.dataset.title)
     },1000)
   },
   getreply(e){
     console.log(e);
    
     
    wx.request({
      url: 'https://zujieba.com/Api/translate/questions.html',
      data:{title:e},
      method:'POST',
      success:(res)=>{
        console.log(res);
       let node =res.data.data.content
       let obj={}
       obj.value=node
        obj.avatar="/img/12.png"
       let list=this.data.list.concat(obj)
       this.setData({list})
     
       
      }
    })
    // let obj={}
    // obj.value='就在这看啊，你想去哪看了555555555555555555555555555555555555555555'
    
    
    // obj.avatar="/img/12.png"
    // let list=this.data.list.concat(obj)
    // this.setData({list})
   },
   inputvalue(e){
     let value=e.detail.value
     this.setData({
       value
     })
   },
   send(){
     if(this.data.value){
      let obj={}
      obj.value=this.data.value
      
      
      obj.avatar=wx.getStorageSync('avatarUrl')
      let list=this.data.list.concat(obj)
      this.setData({list,value:''})
      this.getreply(this.data.value)
     }
   },
   getdata(){
     wx.request({
       url: 'https://zujieba.com/Api/translate/index.html',
       method:'POST',
       success:(res)=>{
         console.log(res);
         this.setData({
           title:res.data.data.title,
           sql:res.data.data.sql
         })
         
       }
     })
   },
  // 防抖函数
   debonuce(fn,wait){
     var timer=this.data.timer
     clearTimeout(timer)
      timer= setTimeout(()=>{
         fn()
       },wait)
       this.setData({
         timer
       })
   }
 
})